﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Sweepids.Models.Object;
using Sweepids.Models.Dao;

namespace Sweepids.Controllers
{
    public class HomeController : Controller
    {

        public ActionResult Index()
        {
            try
            {
                var user = (User)Session["User"];
                user.Fill();
                return View(user);
            }
            catch (Exception)
            {
                TempData["Error"] = "There was trouble getting the current user in the session, please log in again.";
                return RedirectToAction("Index", "Login");
            }
        }

        public ActionResult BuySweeps(int value)
        {
            try
            {
                var user = (User)Session["User"];
                var userDao = new UserDao();

                user.SweepsOwned += value;
                userDao.Update(user);

                TempData["Success"] = "You successfully bought some sweeps.";
                return RedirectToAction("Index", "Home");
            }
            catch (Exception)
            {
                TempData["Error"] = "Something went wrong buying sweeps.";
                return RedirectToAction("Index", "Home");
            }
        }
    }
}
